//
//  AddFishpondShowView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/19.
//

#import "AddFishpondShowView.h"
@interface AddFishpondShowView ()

@property (nonatomic ,strong) UIView * makeView;
@property (nonatomic ,strong) void(^block)(BOOL isComplex);
@property (nonatomic ,assign) CGFloat viewH;

@property (nonatomic ,strong) UIButton * leftbtn;
@property (nonatomic ,strong) UILabel * leftLab;
@property (nonatomic ,strong) UIButton * rightbtn;
@property (nonatomic ,strong) UILabel * rightLab;


@end
@implementation AddFishpondShowView

+ (void)showViewWith:(void(^)(BOOL isComplex))block{

    AddFishpondShowView * view = [AddFishpondShowView new];
    [[DTKTool getCurrentVC].view addSubview:view];
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    view.viewH = kwt(268) + KSafeAreaBottomHeight;
    view.block = block;
    UIView * makeView = [UIView new];
    view.makeView = makeView;
    makeView.backgroundColor = UIColor.whiteColor;
    makeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, view.viewH);
    [view addSubview:makeView];
    [DTKTool BFYJ:kwt(15) andView:makeView andCorner:UIRectCornerTopLeft|UIRectCornerTopRight andSize: CGRectMake(0, 0 ,SCREEN_WIDTH, view.viewH)];
    
//    view.userInteractionEnabled = YES;
//    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(dismiss)]];
    makeView.userInteractionEnabled = YES;
    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(noclick)]];
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(dismiss)]];
    makeView.userInteractionEnabled = YES;
    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(noclick)]];
    
    UILabel * titlab = [DTKTool labelWithText:@"创建池塘" andFont:kCFont(18) andTextColor:KcolorHex(@"#424242")];
    [makeView addSubview:titlab];
    [titlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.top.offset(kwt(20));
    }];
    
    UIButton * btn = [UIButton buttonWithType:0];
    [btn setImage:[UIImage imageNamed:@"close_icon"] forState:UIControlStateNormal];
    btn.addTarget(view,@selector(dismiss));
    [makeView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(26));
        make.centerY.equalTo(titlab);
    }];
    
    UIButton * leftbtn = [UIButton buttonWithType:0];
    view.leftbtn = leftbtn;
    [leftbtn addTarget:view action:@selector(leftBtnclick) forControlEvents:UIControlEventTouchUpInside];
    [leftbtn addTarget:view action:@selector(leftBtnAY) forControlEvents:UIControlEventTouchDown];
    [leftbtn addTarget:view action:@selector(leftBtnOutside) forControlEvents:UIControlEventTouchUpOutside];
    
//    UILongPressGestureRecognizer *LongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:view action:@selector(LongPressmethod)];
//    LongPress.minimumPressDuration = 1;
//    LongPress.delegate = view;
//    LongPress.allowableMovement = kwt(50);
//    [leftbtn addGestureRecognizer: LongPress];
    
    leftbtn.backgroundColor = KcolorHex(@"#EFF4FB");
    [DTKTool YJ:kwt(10) andView:leftbtn];
    [makeView addSubview:leftbtn];
    [leftbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(60));
        make.left.offset(kwt(15));
        make.width.height.offset(kwt(165));
    }];
    UIImageView * leftimg = kimageView(@"single 1");
    [leftbtn addSubview:leftimg];
    [leftimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(15));
        make.width.height.offset(kwt(110));
        make.centerX.offset(0);
    }];
    UILabel * leftlab = [DTKTool labelWithText:@"单个池塘" andFont:kFont(18) andTextColor:KcolorHex(@"#424242")];
    [leftbtn addSubview:leftlab];
    view.leftLab = leftlab;

    [leftlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(132));
        make.centerX.offset(0);
    }];
    
    UIButton * rightbtn = [UIButton buttonWithType:0];
    view.rightbtn = rightbtn;
    [rightbtn addTarget:view action:@selector(rightBtnclick) forControlEvents:UIControlEventTouchUpInside];
    [rightbtn addTarget:view action:@selector(rightBtnAY) forControlEvents:UIControlEventTouchDown];
    [rightbtn addTarget:view action:@selector(rightBtnOutside) forControlEvents:UIControlEventTouchUpOutside];
    
    rightbtn.backgroundColor = KcolorHex(@"#EFF4FB");
    [DTKTool YJ:kwt(10) andView:rightbtn];
    [makeView addSubview:rightbtn];
    [rightbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(60));
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(165));
    }];
    UIImageView * rightimg = kimageView(@"multiple");
    [rightbtn addSubview:rightimg];
    [rightimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(15));
        make.width.height.offset(kwt(110));
        make.centerX.offset(0);
    }];
    UILabel * rightlab = [DTKTool labelWithText:@"多个池塘" andFont:kFont(18) andTextColor:KcolorHex(@"#424242")];
    [rightbtn addSubview:rightlab];
    view.rightLab = rightlab;
    [rightlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(132));
        make.centerX.offset(0);
    }];
    
     
    [view show];
        
    
}
- (void)leftBtnOutside{
    [DTKTool YJBK:kwt(10) andView: self.leftbtn andWidth:0 andColor:KcolorHex(@"#2A79FC")];
    self.leftLab.textColor = KcolorHex(@"#424242");
}

- (void)rightBtnOutside{
    [DTKTool YJBK:kwt(10) andView: self.rightbtn andWidth:0 andColor:KcolorHex(@"#2A79FC")];
    self.rightLab.textColor = KcolorHex(@"#424242");
}
- (void)leftBtnAY{
    [DTKTool YJBK:kwt(10) andView: self.leftbtn andWidth:1 andColor:KcolorHex(@"#2A79FC")];
    self.leftLab.textColor = KcolorHex(@"#2A79FC");
}
- (void)rightBtnAY{
    [DTKTool YJBK:kwt(10) andView: self.rightbtn andWidth:1 andColor:KcolorHex(@"#2A79FC")];
    self.rightLab.textColor = KcolorHex(@"#2A79FC");
}

- (void)leftBtnclick{
    if(self.block){
        self.block(NO);
        [self dismiss];
    }
}

- (void)rightBtnclick{
    if(self.block){
        self.block(YES);
        [self dismiss];
    }
}


- (void)show{
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT - self.viewH , SCREEN_WIDTH, self.viewH);
    }];
}
- (void)noclick{}
- (void)dismiss{
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT , SCREEN_WIDTH, self.viewH);
    } completion:^(BOOL finished) {
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self removeFromSuperview];
    }];
}


@end
